package com.snailhd.framework.i18n.nacos.file.parse;

import org.yaml.snakeyaml.Yaml;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author snailhd
 */
public class YamlFileParser extends AbstractFileParser {

    @Override
    public ConcurrentHashMap<String, String> parse(String text) throws IOException {
        Yaml yaml = new Yaml();
        Map<String,Object> map = yaml.load(text);
        ConcurrentHashMap<String, String> re = new ConcurrentHashMap<>(map.size());
        map.forEach(
                (k,v) -> re.put(k,v!=null ? String.valueOf(v):null)
        );
        return re;
    }
}
